SHELL=/bin/bash

top_builddir=@top_builddir@
top_srcdir=@top_srcdir@
prefix=@prefix@
srcdir=@srcdir@

LIBTOOL=libtool
CC=@CC@
VALAC=@VALAC@
CFLAGS=-g -Wall -I$(top_builddir)/src @GLIB_CFLAGS@ @GOBJECT_CFLAGS@ \
	@GEE_CFLAGS@ @CLUTTER_CFLAGS@ @CAIRO_CFLAGS@ @PANGO_CFLAGS@ @GDK_CFLAGS@
LDFLAGS=-g @GLIB_LIBS@ @GOBJECT_LIBS@ @GEE_LIBS@ @CLUTTER_LIBS@ @CAIRO_LIBS@ \
	@PANGO_LIBS@ @GDK_LIBS@ -lGL
VALAFLAGS=--vapidir $(top_srcdir)/vapi --pkg glib-2.0 --pkg gee-1.0 --pkg \
	clutter-liquidity-0.6 --pkg cairo-liquidity --pkg pango --pkg gdk-2.0 \
	--pkg gl-liquidity --pkg gdk-pixbuf-2.0
VERSIONINFO=@VERSIONINFO@

LIQUIDITY_VALA_SRC=actor-model.vala animatable.vala animation.vala \
	bloom-filter.vala cairo-actor.vala cairo-software-actor.vala \
	constraint.vala constraint-attribute.vala constraint-layout-manager.vala \
	container-model.vala filter.vala filter-behavior.vala float.vala \
	geometry-primitives.vala layout-manager.vala transaction.vala \
	unit-functions.vala update.vala
LIQUIDITY_C_SRC=
TESTS_VALA_SRC=bloom.vala cairo.vala hierarchy.vala position.vala
VAPI=vapi/cairo-liquidity.vapi vapi/clutter-liquidity-0.6.vapi \
	 vapi/gl-liquidity.vapi

all:	libliquidity.la

LIQUIDITY_VALA_FP_SRC=$(LIQUIDITY_VALA_SRC:%=src/liquidity/%)
LIQUIDITY_C_FP_SRC=$(LIQUIDITY_C_SRC:%=src/liquidity/%)
LIQUIDITY_VALA_C_FP_SRC=$(LIQUIDITY_VALA_FP_SRC:%.vala=%.c)
LIQUIDITY_FP_SRC=$(LIQUIDITY_VALA_C_FP_SRC) $(LIQUIDITY_C_FP_SRC)
LIQUIDITY_FP_OBJ=$(LIQUIDITY_FP_SRC:%.c=%.lo)

QUIET=@qp() { local tag=$$1 ; shift ; printf "  %-12s %s\n" "$$tag" $@ ; $$* \
	; } ; qp

libliquidity.la:	$(LIQUIDITY_FP_OBJ) 
	$(QUIET) "LINK [LT]" $(LIBTOOL) --silent --mode=link $(CC) $(LDFLAGS) -o \
	   	$@ -rpath $(prefix)/lib -export-symbols-regex '^liquidity\w+$$' \
		-version-info $(VERSIONINFO) $(LIQUIDITY_FP_OBJ)

%.lo:	%.c
	$(QUIET) "CC [LT]" $(LIBTOOL) --silent --mode=compile $(CC) $(CFLAGS) -c \
		-o $@ $^

$(LIQUIDITY_VALA_C_FP_SRC):	liquidity-vala.stamp $(VAPI)

liquidity-vala.stamp:	$(LIQUIDITY_VALA_FP_SRC)
	$(QUIET) "VALAC" $(VALAC) $(VALAFLAGS) --library liquidity --basedir src \
		-C $^ && touch $@

.PHONY: clean tests

TESTS_VALA_FP_SRC=$(TESTS_VALA_SRC:%=t/%)
TESTS_VALA_C_FP_SRC=$(TESTS_VALA_FP_SRC:%.vala=%.c)
TESTS_FP_OBJ=$(TESTS_VALA_C_FP_SRC:%.c=%.o)
TESTS_FP_EXE=$(TESTS_VALA_C_FP_SRC:%.c=%)

tests:	$(TESTS_FP_EXE)

$(TESTS_FP_EXE):	libliquidity.la

$(TESTS_FP_EXE):	%:	%.o
	$(QUIET) "LINK [LT]" $(LIBTOOL) --silent --mode=link $(CC) $(CFLAGS) -o \
		$@ $^ libliquidity.la

$(TESTS_FP_OBJ):	%.o:	%.c
	$(QUIET) CC $(CC) $(CFLAGS) -I. -Isrc -c -o $@ $^

$(TESTS_VALA_C_FP_SRC):	libliquidity.la $(VAPI)

$(TESTS_VALA_C_FP_SRC):	%.c:	%.vala
	$(QUIET) VALAC $(VALAC) $(VALAFLAGS) --vapidir $(top_builddir) --pkg \
		liquidity --basedir . -C $< 

clean:
	rm -f $(LIQUIDITY_VALA_C_FP_SRC) $(LIQUIDITY_FP_OBJ) \
		libliquidity.la $(TESTS_FP_EXE) $(TESTS_FP_OBJ) \
		$(TESTS_VALA_C_FP_SRC) liquidity-vala.stamp

#
#	Boilerplate Autoconf remaking
#

$(srcdir)/configure:	configure.ac aclocal.m4
	cd '$(srcdir)' && autoconf

Makefile:	Makefile.in config.status
	./config.status

config.status:	configure
	./config.status --recheck

